package it.rap.applications.birt.report.accounts.core;

import java.util.logging.Level;
import java.util.logging.Logger;

import org.eclipse.rap.rwt.RWT;
import org.eclipse.rap.rwt.service.ServiceHandler;
import org.eclipse.rap.rwt.service.ServiceManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;

import it.rap.applications.birt.report.accounts.services.BirtDownloadServiceHandler;
import it.rap.applications.birt.report.accounts.services.DownloadServiceHandler;
import it.rap.applications.container.IContainerPage;
import it.rap.applications.contributions.manager.services.IDownloadServiceHandler;

public class BirtReport implements IContainerPage {

	private Browser browser;	

	private final static int COMPOSITE_COLUMN = 1;
 	/**
	 * @wbp.parser.entryPoint
	 */
	public void wBuilderEntriPoint(Composite parent){
		Composite contentComp = new Composite(parent, SWT.NONE);
		this.createControl(contentComp);
	}
	
	@Override
	public void createControl(Composite parent) {
		parent.setLayout( new FillLayout() );
		String reportHtml = "";
		
		ServiceManager manager = RWT.getServiceManager();
		IDownloadServiceHandler handler = new DownloadServiceHandler();	
		IDownloadServiceHandler birtHandler = new BirtDownloadServiceHandler();	
		
		try{
			manager.registerServiceHandler( DownloadServiceHandler.ID, (ServiceHandler)handler );
			manager.registerServiceHandler( BirtDownloadServiceHandler.ID, (ServiceHandler)birtHandler );
		} catch( IllegalArgumentException e ){
			Logger.getAnonymousLogger().log(Level.SEVERE, e.getMessage());
		}
			
		
		try {
			HTMLView htmlView = new HTMLView("reportTest.rptdesign");	
			htmlView.createReport();
			reportHtml = htmlView.doReport();
			browser = new Browser( parent, SWT.NONE );
			browser.setText( reportHtml );
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
